<template>
  <div class="edit L-scroll-container" ref="scrollContainer">
    <div id="fieldsDom">
      <van-overlay :show="overlayShow" :z-index="1000">
        <div style="
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
          ">
          <van-loading type="spinner" color="#1989fa">请稍候...</van-loading>
        </div>
      </van-overlay>

      <!-- <van-sticky>
        <van-row type="flex" align="center" class="L-top-bar">
          <van-col :span="4">
            <span style="font-size:14px">退回</span>
          </van-col>
          <van-col :span="16"><span style="font-weight:bold;font-size:16px">{{title}}</span></van-col>
          <van-col :span="4">
            <span style="font-size:14px">跳过此步</span>
          </van-col>
        </van-row>
      </van-sticky> -->

      <headcom v-if="JSON.stringify(headdata) !== '{}'" :jsondata="headdata"></headcom>

      <div class="L-container" style="padding-top: 0">
        <van-sticky>
          <div class="L-flex-row" style="
              background: #fff;
              padding: 0 5px;
              border-bottom: 1px solid #fafafa;
            ">
            <div>
              <span style="font-size: 16px; font-weight: bold">动作</span>
              <span style="color: #ff9100; margin-left: 10px">{{
                stitle
                }}</span>
            </div>

            <div>
              <span class="L-btn-gray" @click="getnew('new')" v-if="newline">添加一行</span>
              <span class="L-btn-gray" @click="savelog('skip')" v-if="canskip && canskip != 'false'">跳过</span>
            </div>
          </div>
        </van-sticky>

        <div :style="actionType != '签到' && actionType != '签退'
            ? 'margin-bottom: 60px;'
            : ''
          ">
          <div v-for="(jsondata, index) in jsondatas" :key="jsondata[idobject + '_id']" class="L-block">
            <van-icon name="clear" class="L-close-icon" v-if="idobject != headobject && jsondatas.length > 1"
              @click="handleDelete(index)" />
            <template v-for="item in jsondata.head">
              <template>
                <div :key="'div_' + jsondata[idobject + '_id'] + item.grouptitle">
                  <template v-for="itemdata in item.groupvalue">
                    <div v-if="fields.indexOf(itemdata.sField) >= 0"
                      :key="'field' + jsondata[idobject + '_id'] + itemdata.ID">
                      <!-- {{itemdata.sUIType}} -->
                      <!-- <div style="border-bottom:1px solid #ebedf0" v-if="fields.indexOf(itemdata.sField) >= 0" :key="'field' + jsondata[idobject + '_id'] + itemdata.ID"> -->
                      <div v-if="itemdata.sField == 'distance'">
                        <van-field placeholder="系统自动填充" :id="itemdata.sField" readonly v-model="itemdata.value"
                          :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                      </div>
                      <idatetime ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'datetime'" />
                      <icode ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'code'" />
                      <ienum ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'enum'" :jsondata="jsondata"
                        :idobject="idobject" />
                      <iref ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'ref'"
                        :clickmodel.sync="clickmodel" :clickfrom.sync="clickfrom" :clickindex.sync="clickindex"
                        :jsondataindex.sync="jsondataindex" :jsondatai="index" :jsondata="jsondata" />
                      <ibool ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'bool'" :jsondata="jsondata"
                        :idobject="idobject" />
                      <ifile ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'file'" :jsondata="jsondata" />
                      <ipicture ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'picture'"
                        :jsondata="jsondata" />
                      <istring ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'string'" :jsondata="jsondata"
                        :idobject="idobject" />
                      <!-- <imap ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'map'" :jsondata="jsondata" :item="item" /> -->
                      <imap2 ishead :itemdata="itemdata" v-else-if="itemdata.sUIType == 'map'" :jsondata="jsondata"
                        :item="item" :center.sync="center" @distanceInit="distanceInit"
                        @savePositionInfo="savePositionInfo" />
                      <istring ishead :itemdata="itemdata" v-else :jsondata="jsondata" :idobject="idobject" />
                    </div>
                  </template>
                </div>
              </template>
            </template>
          </div>
        </div>
      </div>
    </div>

    <div class="roundCir" v-if="actionType == '签到'" @click="qiandao">
      签到<br /><span style="font-size: 20px">{{ this.qiandaotime }}</span>
    </div>
    <div class="roundCir" v-if="actionType == '签退'" @click="qiantui">
      签退<br /><span style="font-size: 20px">{{ this.qiandaotime }}</span>
    </div>

    <!-- <div v-if="actionType == '签到' && isqdshow" @click="qiandao" class="qiandaoBtn" :style="'box-sizing: border-box; text-align: center; height: ' + qiandaobtnheight + 'px; min-height: 150px; padding-top: ' + qiandaobtntop + 'px;'">
      <button class='roundCir' >签到<br><span style="font-size: 20px">{{ this.qiandaotime }}</span></button>
    </div>
    <div v-if="actionType == '签退' && isqdshow" @click="qiantui" class="qiandaoBtn" :style="'box-sizing: border-box; text-align: center; height: ' + qiandaobtnheight + 'px; min-height: 150px; padding-top: ' + qiandaobtntop + 'px;'">
      <button class='roundCir' >签退<br><span style="font-size: 20px">{{ this.qiantuitime }}</span></button>
    </div> -->
    <!-- <van-tabbar v-if="actionType != '签到' && actionType != '签退'" v-model="active" safe-area-inset-bottom>
      <van-tabbar-item @click="save">保存</van-tabbar-item> -->
    <!-- <van-tabbar-item @click="savelog('skip')" v-if="!ended">跳过</van-tabbar-item> -->
    <!-- <van-tabbar-item @click="savesubmit">保存并提交</van-tabbar-item> -->
    <!-- </van-tabbar> -->
    <div v-if="actionType != '签到' && actionType != '签退'" class="savebtn">
      <van-button type="info" @click="save" style="width: 90vw">{{
        scenario.scenarioInfo.length &&
          scenario.scenarioInfo.length > nowIndex + 1 &&
          !ended
          ? "提交并继续"
          : "提交"
      }}</van-button>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import {
  Panel,
  Dialog,
  Search,
  List,
  Cell,
  PullRefresh,
  Toast,
  Tabbar,
  TabbarItem,
  Popup,
  DatetimePicker,
  ActionSheet,
  Tab,
  Tabs,
  Collapse,
  CollapseItem,
  Checkbox,
  CheckboxGroup,
  Uploader,
  Overlay,
  Loading,
  Rate,
  NumberKeyboard,
} from "vant";
import qs from "qs";
import useInput from "@/utils/useinput";
import * as dd from "dingtalk-jsapi";
import wx from "weixin-js-sdk";
import headcom from "@/components/scenario/pageHead.vue";
import imap2 from "../../components/input/imap2.vue";
Vue.use(Panel)
  .use(Dialog)
  .use(useInput)
  .use(Search)
  .use(List)
  .use(Cell)
  .use(PullRefresh)
  .use(Toast)
  .use(Tabbar)
  .use(TabbarItem)
  .use(Popup)
  .use(DatetimePicker)
  .use(ActionSheet)
  .use(Tab)
  .use(Tabs)
  .use(Collapse)
  .use(CollapseItem)
  .use(Checkbox)
  .use(CheckboxGroup)
  .use(Uploader)
  .use(Overlay)
  .use(Loading)
  .use(Rate)
  .use(NumberKeyboard);
export default {
  that: this,
  name: "edit",
  components: { headcom, imap2 },
  data() {
    let _this = this;
    return {
      action: {},
      stitle: this.$route.query.stitle,
      idobject: this.$route.query.idobject,
      submittype: this.$route.query.atype,
      headobject: this.$route.query.headobject,
      headid: this.$route.query.headid,
      fields: this.$route.query.fields,
      scenario: {},
      lastActionIndex: this.$route.query.lastActionIndex,
      nowIndex: this.$route.query.nowIndex,
      ended: this.$route.query.ended,
      actionType: this.$route.query.actionType,
      canskip: this.$route.query.canskip,
      itemids: JSON.parse(this.$route.query.itemid),
      jsondatas: [],
      headdata: {},
      index: 0,
      active: 0,
      activeBodyNams: [""],
      clickmodel: {},
      isLoad: false,
      clickfrom: "",
      clickindex: 0,
      jsondataindex: 0,
      isDisable: false,
      overlayShow: false,
      qiandaotime: "",
      qiantuitime: "",
      jsonindex: 0,
      qiandaobtnheight: 0,
      qiandaobtntop: 0,
      center: [0, 0],
      newline: false,
      isqdshow: true,
      isqdtime: null,
      lngLatDataSources: "",
      weixinPositionInfo: "",
      gaodePositionInfo: "",
    };
  },
  created() {
    //console.log('created......', this.canskip, this.lastActionIndex, this.nowIndex, this.actionType, this.$route.query, this.scenario, this.itemids)
    // this.fetchData()
    this.scenario = JSON.parse(localStorage.getItem("scenarioData"));

    let _this = this;
    document.title = this.title;
    //console.log('document.title', document.title)
    if (dd.env.platform !== "notInDingTalk") {
      dd.ready(function () {
        dd.biz.navigation.setTitle({
          title: _this.$route.query.stitle,
        });
      });
    }
  },
  mounted: function () {
    //console.log('mounted......', this.canskip, this.lastActionIndex, this.nowIndex, this.actionType, this.$route.query, this.scenario, this.itemids)
    let that = this;
    document.title = this.$route.query.stitle;
    // //console.log('action ...')
    // //console.log('start action')
    // //console.log('fields', this.fields, this.ended)
    this.qiandaotime = this.currenttime().split(" ")[1].substring(0, 5);
    this.qiantuitime = this.currenttime().split(" ")[1].substring(0, 5);
    if (!this.isLoad) {
      this.axios({
        method: "post",
        url: "/api/" + this.headobject + ".check.do",
        data: qs.stringify({ [this.headobject + "_id"]: this.headid }),
      })
        .then((res) => {
          this.headdata = res.data.jsondata;
          // //console.log('headdata', this.headdata)
          //console.log('getnew', this.itemids)
          for (let i = 0; i < this.itemids.length; i++) {
            this.getnew(this.submittype);
          }
        })
        .catch((res) => {
          this.reserror(res);
        });

      /* setTimeout(function () {
        that.getDistance(function (dis) {
          if (dis) {
            // document.getElementById('distance').value = dis
            for (let i = 0; i < that.itemids.length; i++) {
              for (let groupindex in that.jsondatas[i].head) {
                let itemgroup = that.jsondatas[i].head[groupindex].groupvalue
                for (let itemindex in itemgroup) {
                  let itemdata = itemgroup[itemindex]
                  if (itemdata.sField == 'distance') {
                    itemdata['value'] = dis
                  }
                }
              }
            }
          }
        })
      }, 1000) */
      // if (this.actionType == '签到' || this.actionType == '签退') {
      //   that.isqdtime = setTimeout(() => {
      //     if (!that.isqdshow) {
      //       Dialog.confirm({
      //         message: '定位失败，请检查权限',
      //         confirmButtonText: '重新定位',
      //         cancelButtonText: '忽略'
      //       }).then(() => {
      //         window.location.reload()
      //       }).catch(() => {
      //       })
      //       that.isqdshow = true
      //     }
      //     Toast.clear()
      //   }, 7000)
      // }
    }
  },
  beforeDestroy() {
    clearTimeout(this.isqdtime);
  },
  updated() {
    let fieldsDom = document.getElementById("fieldsDom");
    if (fieldsDom) {
      this.qiandaobtnheight =
        document.documentElement.clientHeight - fieldsDom.offsetHeight;
      // //console.log('qiandaoHight', fieldsDom.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight, this.qiandaobtnheight)
      if (this.qiandaobtnheight > 150) {
        this.qiandaobtntop = (this.qiandaobtnheight - 150) / 2;
      } else {
        this.qiandaobtntop = 0;
      }
    }
  },
  methods: {
    savePositionInfo(info = "", source = "") {
      // //console.log("savePositionInfo$$$$$$$$",savePositionInfo)
      if (source === "weixin") {
        this.weixinPositionInfo = info;
      }
      if (source === "gaode") {
        this.gaodePositionInfo = info;
      }
    },

    distanceInit(center, lngLatDataSources = "gaode") {
      // 判读是否是高德返回的定位
      if (lngLatDataSources) {
        this.lngLatDataSources = center;
      }

      let that = this;
      that.center = center;
      that.getDistance(function (dis) {
        if (dis) {
          // document.getElementById('distance').value = dis
          for (let i = 0; i < that.itemids.length; i++) {
            for (let groupindex in that.jsondatas[i].head) {
              let itemgroup = that.jsondatas[i].head[groupindex].groupvalue;
              for (let itemindex in itemgroup) {
                let itemdata = itemgroup[itemindex];
                if (itemdata.sField == "distance") {
                  itemdata["value"] = dis;
                }
              }
            }
          }
        }
      });
    },
    handleDelete(index) {
      this.$delete(this.jsondatas, index);
      this.jsonindex--;
      //console.log('this.jsondatas', this.jsondatas)
    },
    scrollToBottom() {
      const container = this.$refs.scrollContainer;

      //console.log('container', container)

      // container.scrollTop = container.scrollHeight;
      container.scrollTo({
        top: container.scrollHeight,
        behavior: "smooth",
      });
    },
    delnew(index) {
      //console.log('delnew', index)
      if (this.jsondatas.length > 1) {
        this.jsondatas.splice(index, 1);
      } else {
        Toast("至少保留一条数据");
      }
    },
    getnew(stype) {
      let index = this.jsonindex++;
      let zdysArr = this.scenario.scenarioInfo[this.nowIndex]?.zdys;
      //console.log('zdys', this.nowIndex, zdysArr)
      /* if (zdysArr) {
        for (let j = 0; j < this.headdata.Details.length; j++) {
          let detail = this.headdata.Details[j]
          for (let k = 0; k < detail.groupvalue.length; k++) {
            let field = detail.groupvalue[k]
            for (let i = 0; i < zdysArr.length; i++) {
              if (field.sField == zdysArr[i].field) {
                zdysArr[i].value = field
              }
            }
          }
        }
      } */

      let data = {
        sobject: this.idobject,
        [this.idobject + "_id"]: this.itemids[index],
        fields: JSON.stringify(this.fields),
        zdys: JSON.stringify(zdysArr),
        headid: this.headid,
        headobject: this.headobject,
      };

      //console.log('getnew scenario', zdysArr, this.headdata)
      this.axios({
        method: "post",
        // url: '/api/' + this.idobject + '.' + this.submittype + '.do',
        url: "/api/scenario.getaction.do",
        data: qs.stringify(data),
      })
        .then((res) => {
          //console.log('getnew jsondata res', res)
          if (res.data.flag === "1") {
            Toast(res.data.des);
            if (res.data.des && res.data.des.indexOf("登录过期") >= 0) {
              this.loginout();
            }
          } else {
            // this.jsondatas[index] = res.data.jsondata
            this.newline = res.data.jsondata.newline;
            let resJsondata = res.data.jsondata;
            resJsondata["stype"] = stype;

            Vue.set(this.jsondatas, index, resJsondata);
            // this.$forceUpdate()
            if (!this.itemids[index]) {
              Vue.set(this.itemids, index, resJsondata[this.idobject + "_id"]);
            }
            //console.log('getnew jsondatas', this.jsondatas, this.itemids)
            // this.$forceUpdate()

            this.$nextTick(() => {
              // this.scrollToBottom()
            });
          }
        })
        .catch((res) => {
          this.reserror(res);
        });
    },
    save() {
      //console.log('save', this.scenario)
      if (!this.isDisable) {
        this.overlayShow = true;
        this.isDisable = true;
        for (let i = 0; i < this.itemids.length; i++) {
          let data = {};
          data[this.idobject + "_id"] = this.itemids[i];
          for (let groupindex in this.jsondatas[i].head) {
            let itemgroup = this.jsondatas[i].head[groupindex].groupvalue;
            for (let itemindex in itemgroup) {
              let itemdata = itemgroup[itemindex];
              if (itemdata.sUIType === "ref") {
                data[itemdata.idObject + "_" + itemdata.sField] =
                  itemdata.valuehidden;
                data[itemdata.idObject + "_" + itemdata.sField + "_ref"] =
                  itemdata.value;
              } else if (itemdata.sUIType === "enum") {
                data[itemdata.idObject + "_" + itemdata.sField] =
                  itemdata.valuehidden;
                data[itemdata.idObject + "_" + itemdata.sField + "_enum"] =
                  itemdata.value;
              } else if (
                itemdata.sUIType === "file" ||
                itemdata.sUIType === "picture"
              ) {
                data[itemdata.idObject + "_" + itemdata.sField] =
                  itemdata.valuehidden;
                data[itemdata.idObject + "_" + itemdata.sField + "_title"] =
                  itemdata.value;
              } else {
                data[itemdata.idObject + "_" + itemdata.sField] =
                  itemdata.value;
              }
            }
          }

          // 位置信息不入库

          data["weixinPositionInfo"] = this.weixinPositionInfo;
          data["gaodePositionInfo"] = this.gaodePositionInfo;

          this.axios({
            method: "post",
            url:
              "/api/" +
              this.idobject +
              "." +
              this.jsondatas[i].stype +
              "save.do",
            data: qs.stringify(data),
          })
            .then((res) => {
              this.isDisable = false;
              this.overlayShow = false;
              if (res.data.flag === "0") {
                // Toast('保存成功')
                this.savelog("end");
              } else {
                Toast(res.data.des);
                if (res.data.des && res.data.des.indexOf("登录过期") >= 0) {
                  this.loginout();
                }
              }
              //console.log(res)
            })
            .catch((res) => {
              this.isDisable = false;
              this.overlayShow = false;
              //console.log(res)
            });
        }
      }
    },
    qiandao() {

      let projectData = require('@/project.json')
      console.log("projectData.project",projectData.project)
      // 迈克维特判
      if (projectData.project == 'mkw/') {
        let picValid = false;
        const { emcontacttype } = this.$route.query;
        if (emcontacttype !== "医院拜访") {
          for (let i = 0; i < this.itemids.length; i++) {
            for (let groupindex in this.jsondatas[i].head) {
              let itemgroup = this.jsondatas[i].head[groupindex].groupvalue;
              for (let itemindex in itemgroup) {
                let itemdata = itemgroup[itemindex];
                if (
                  itemdata.sField == "bapctp" &&
                  itemdata.valuelist?.length > 0
                ) {
                  picValid = true;
                }
              }
            }
          }
        } else if (emcontacttype == "医院拜访") {
          picValid = true;
        }
        if (!picValid) return Toast("拜访类型不为医院拜访，必须要提交照片");
      }



      Toast.loading({
        message: "执行中...",
        forbidClick: true,
        duration: 2000,
      });
      let that = this;
      this.getDistance(function (dis) {
        //console.log('this.getDistance()', dis, that.itemids)
        if (true) {
          for (let i = 0; i < that.itemids.length; i++) {
            for (let groupindex in that.jsondatas[i].head) {
              let itemgroup = that.jsondatas[i].head[groupindex].groupvalue;
              for (let itemindex in itemgroup) {
                let itemdata = itemgroup[itemindex];
                if (itemdata.sField === "dbegin") {
                  itemdata.value = that.currenttime();
                }
              }
            }
          }
          that.save();
        } else {
          alert("定位失败或超出可签到范围");
        }
      });
    },
    qiantui() {
      Toast.loading({
        message: "执行中...",
        forbidClick: true,
        duration: 2000,
      });
      let that = this;
      this.getDistance(function (dis) {
        if (true) {
          for (let i = 0; i < that.itemids.length; i++) {
            for (let groupindex in that.jsondatas[i].head) {
              let itemgroup = that.jsondatas[i].head[groupindex].groupvalue;
              for (let itemindex in itemgroup) {
                let itemdata = itemgroup[itemindex];
                if (itemdata.sField === "dend") {
                  itemdata.value = that.currenttime();
                }
              }
            }
          }
          that.save();
        } else {
          alert("定位失败或超出可签到范围");
        }
      });
    },
    getDistance(func) {
      //console.log('getDistance func', this.center)
      this.axios({
        method: "post",
        url: "/api/scenario.getdistance.do",
        data: qs.stringify({
          center: JSON.stringify(this.center),
          bo: this.headobject,
          id: this.headid,
        }),
      })
        .then((res) => {
          // //console.log('scenario.getdistance.do', res, res.status, res.data.distance)
          func(res.data.distance);
          this.isqdshow = true;
        })
        .catch((res) => {
          Toast("系统异常，请联系管理员！");
          //console.log('系统异常，请联系管理员！', res)
        });
    },
    savelog(states) {
      let that = this;
      let data = {
        idscenario: this.$route.query.scenarioId,
        idaction: this.$route.query.actionId,
        sobject: this.headobject,
        iddata: this.headid,
        toobject: this.idobject,
        toiddata: JSON.stringify(this.itemids),
        states: states,
        ended: this.ended,
      };
      //console.log('savelog', this.itemids, data, '---', this.scenario.scenarioInfo.length, this.scenario.scenarioInfo.length > this.lastActionIndex + 1, !this.ended)
      // alert(this.scenario.scenarioInfo.length + ' ' + this.lastActionIndex)
      this.axios({
        // 存动作记录
        method: "post",
        url: "/api/scenario.savelog.do",
        data: qs.stringify(data),
      })
        .then((res) => {
          if (res.data.flag === "0") {
            // 如果有下个动作跳到下个动作页面
            console.log(
              "///",
              res.data,
              this.scenario.scenarioInfo.length,
              this.nowIndex,
              this.ended
            );
            console.log("///", this.nowIndex + 1);
            const nextIdx = JSON.parse(this.nowIndex) + 1;
            if (
              this.scenario.scenarioInfo.length &&
              this.scenario.scenarioInfo.length > nextIdx &&
              !JSON.parse(this.ended)
            ) {
              data["ended"] = "false";
              this.axios({
                method: "post",
                url: "/api/scenario.end.do", // 保存状态
                data: qs.stringify(data),
              })
                .then((res1) => {
                  console.log("res1", res1);
                  if (res1.data.flag === "0") {
                    const nextIndex = JSON.parse(that.nowIndex) + 1;
                    let lastAction = that.scenario.scenarioInfo[nextIndex];
                    that.$router
                      .replace({
                        path: "/action",
                        query: {
                          scenarioId: that.scenario.scenarioId,
                          actionId: lastAction.actionId,
                          itemid: lastAction.toId,
                          headobject: that.headobject,
                          headid: that.headid,
                          idobject: lastAction.toBo,
                          atype: lastAction.toPage,
                          stitle: lastAction.actionName,
                          fields: lastAction.fields,
                          canskip: lastAction.canskip,
                          ended: false,
                          // scenario: JSON.stringify(this.scenario),
                          nowIndex: nextIndex,
                          lastActionIndex: that.lastActionIndex + 1,
                          actionType: lastAction.actionType,
                        },
                      })
                      .catch(function (res) {
                        console.log("replace error", res);
                      });
                  } else {
                    Toast(res.data.des);
                    if (res.data.des && res.data.des.indexOf("登录过期") >= 0) {
                      this.loginout();
                    }
                  }
                })
                .catch((res1) => {
                  //console.log('replace error', res)
                });
            } else if (
              this.scenario.scenarioInfo.length &&
              this.scenario.scenarioInfo.length <= nextIdx
            ) {
              data["ended"] = "true";
              this.axios({
                method: "post",
                url: "/api/scenario.end.do", // 保存状态
                data: qs.stringify(data),
              })
                .then((res1) => {
                  if (res1.data.flag === "0") {
                    this.$router.go(-1);
                    // this.$router.replace({ name: 'card', query: { idobject: this.headobject, itemid: this.headid } })
                  } else {
                    Toast(res.data.des);
                    if (res.data.des && res.data.des.indexOf("登录过期") >= 0) {
                      this.loginout();
                    }
                  }
                })
                .catch((res1) => {
                  //console.log('replace error', res)
                });
            } else {
              // 已完成/已跳过的直接返回
              this.$router.go(-1);
            }
          } else {
            Toast(res.data.des);
            if (res.data.des && res.data.des.indexOf("登录过期") >= 0) {
              this.loginout();
            }
          }
        })
        .catch((res) => {
          this.isDisable = false;
          this.overlayShow = false;
          //console.log(res)
        });
    },
    currenttime() {
      let d = new Date();
      let year = d.getFullYear();
      let month = this.change(d.getMonth() + 1);
      let day = this.change(d.getDate());
      let hour = this.change(d.getHours());
      let minute = this.change(d.getMinutes());
      let second = this.change(d.getSeconds());
      let time =
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second;
      return time;
    },
    change(t) {
      if (t < 10) {
        return "0" + t;
      } else {
        return t;
      }
    },
    addRow(indexName) {
      let bodycopy = JSON.parse(JSON.stringify(this.jsondata.body[indexName]));
      this.jsondata.bodydata[indexName].push(bodycopy);
    },
    delRow(indexName, index) {
      if (this.jsondata.bodydata[indexName].length === 1) {
        Toast("至少保留一条表体行，不能删除！");
        return;
      }
      Dialog.confirm({
        title: "",
        message: "你确定要删除" + indexName + " " + (index + 1) + "吗?",
      })
        .then(() => {
          // on confirm
          this.jsondata.bodydata[indexName].splice(index, 1);
        })
        .catch(() => {
          // on cancel
        });
    },
  },
  activated() {
    let jsondata = this.jsondatas[this.jsondataindex];
    let that = this;
    let a = { aa: "aaa" };
    //console.log('a1', a)
    //console.log('clickmodel1', this.clickmodel)
    //console.log('clickindex1', this.clickindex)
    //console.log('clickindexName1', this.clickindexName)
    //console.log('clickfrom1', this.clickfrom)
    if (this.$store.state.ref_show !== "") {
      this.clickmodel.value = this.$store.state.ref_show;
      this.clickmodel.valuehidden = this.$store.state.ref_id;
      this.clickmodel.errormsg = "";
      let fieldmap = this.clickmodel.fieldmap;
      //console.log('fieldmap', fieldmap)
      if (fieldmap !== undefined && fieldmap.length > 0) {
        let arrFieldmap = fieldmap.split(";");
        let item = this.$store.state.ref_item;
        if (this.clickfrom === "headdata") {
          a.aa = "bbb";
          //console.log(jsondata)
          for (
            let groupindex = 0;
            groupindex < jsondata.head.length;
            groupindex++
          ) {
            let itemgroup = jsondata.head[groupindex];
            for (
              let itemindex = 0;
              itemindex < itemgroup.groupvalue.length;
              itemindex++
            ) {
              let itemdata = itemgroup.groupvalue[itemindex];
              for (let fieldmapindex in arrFieldmap) {
                let arrFieldMapKey = arrFieldmap[fieldmapindex].split(":");
                if (this.$store.state.ref_field === arrFieldMapKey[1]) {
                  continue;
                }
                if (
                  arrFieldMapKey.length === 3 &&
                  arrFieldMapKey[2] !== "" &&
                  this.$store.state.ref_field !== arrFieldMapKey[2]
                ) {
                  continue;
                }
                if (itemdata.sField === arrFieldMapKey[1]) {
                  if (itemdata.sUIType === "ref") {
                    itemdata.value = item[arrFieldMapKey[0] + "_ref"];
                    itemdata.valuehidden = item[arrFieldMapKey[0]];
                  } else if (itemdata.sUIType === "enum") {
                    itemdata.value = item[arrFieldMapKey[0] + "_enum"];
                    itemdata.valuehidden = item[arrFieldMapKey[0]];
                  } else {
                    itemdata.value = item[arrFieldMapKey[0]];
                  }
                }
              }
            }
          }
        } else if (this.clickfrom === "bodydata") {
          a.aa = "ccc";
          for (let itemindex in jsondata.bodydata[this.clickindexName][
            this.clickindex
          ]) {
            let itemdata =
              jsondata.bodydata[this.clickindexName][this.clickindex][
              itemindex
              ];
            for (let fieldmapindex in arrFieldmap) {
              let arrFieldMapKey = arrFieldmap[fieldmapindex].split(":");
              if (this.$store.state.ref_field === arrFieldMapKey[1]) {
                continue;
              }
              if (
                arrFieldMapKey.length === 3 &&
                arrFieldMapKey[2] !== "" &&
                this.$store.state.ref_field !== arrFieldMapKey[2]
              ) {
                continue;
              }
              if (itemdata.sField === arrFieldMapKey[1]) {
                if (itemdata.sUIType === "ref") {
                  itemdata.value = item[arrFieldMapKey[0] + "_ref"];
                  itemdata.valuehidden = item[arrFieldMapKey[0]];
                } else if (itemdata.sUIType === "enum") {
                  itemdata.value = item[arrFieldMapKey[0] + "_enum"];
                  itemdata.valuehidden = item[arrFieldMapKey[0]];
                } else {
                  itemdata.value = item[arrFieldMapKey[0]];
                }
              }
            }
          }
        }
      }
      //console.log('a', a)
      //console.log('clickmodel', this.clickmodel)
      //console.log('clickindex', this.clickindex)
      //console.log('clickindexName', this.clickindexName)
      //console.log('clickfrom', this.clickfrom)
      this.clickmodel = {};
      this.clickindex = 0;
      this.clickindexName = "";
      this.clickfrom = "";
      this.$store.commit("clearRef");
    }
  },
};
</script>

<style scoped>
.L-scroll-container {
  width: 100%;
  height: 100vh;
  overflow: auto;
  /* transition: all 5s; */
}

.L-block {
  background: #f4f4f5;
  margin: 15px auto;
  box-sizing: border-box;
  padding: 10px;
  position: relative;
}

.L-block .L-close-icon {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 99;
  font-size: 24px;
  color: #c0c4cc;
}

.fieldgroup_title {
  text-align: left;
  margin: 0px;
  padding: 25px 15px 15px;
  color: rgba(69, 90, 100, 0.6);
  font-weight: normal;
  font-size: 14px;
}

.roundCir {
  /* min-width: 150px;
  max-width: 150px;
  max-height: 150px;
  min-height: 150px;
  border-radius: 80px;
  font-size: 15px;
  color: white;
  background: #1989fa;
  border: 1px solid white;  */
  display: flex;

  justify-content: center;
  align-items: center;
  flex-direction: column;
  margin-left: 32vw;
  width: 134px;
  height: 134px;
  background: linear-gradient(180deg, #fdc75b 0%, #ff9d02 100%);
  filter: drop-shadow(0 0 9px #ffc523cc);
  border-radius: 50%;
  border: none;
  color: #fff;
}

.savebtn {
  position: fixed;
  z-index: 1000;
  bottom: 0px;
  text-align: center;
  width: 100vw;
  padding-bottom: 5vw;
}

.qiandaoBtn {}
</style>
